namespace XRM.Security.DataAccess.Context
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class RemoveRequestNumberLockTable : DbMigration
    {
        public override void Up()
        {
            AddColumn( "dbo.Request", "CloseDate", c => c.DateTime() );
            Sql( "update Request set CloseDate = CancelDate" );
            DropColumn( "dbo.Request", "CancelDate" );
            DropColumn( "dbo.Request", "Urgency" );

            DropForeignKey("dbo.RequestLockNumber", "SystemUserId", "dbo.SystemUser");
            DropIndex("dbo.RequestLockNumber", new[] { "SystemUserId" });
            DropTable("dbo.RequestLockNumber");
            DropTable("dbo.RequestNumber");
        }
        
        public override void Down()
        {
            AddColumn( "dbo.Request", "Urgency", c => c.Int( nullable: false ) );
            AddColumn( "dbo.Request", "CancelDate", c => c.DateTime() );
            DropColumn( "dbo.Request", "CloseDate" );

            CreateTable(
                "dbo.RequestNumber",
                c => new
                    {
                        RequestNumberId = c.Int(nullable: false, identity: true),
                        Number = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.RequestNumberId);
            
            CreateTable(
                "dbo.RequestLockNumber",
                c => new
                    {
                        RequestLockNumberId = c.Int(nullable: false, identity: true),
                        Number = c.Int(nullable: false),
                        SystemUserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.RequestLockNumberId);
            
            CreateIndex("dbo.RequestLockNumber", "SystemUserId");
            AddForeignKey("dbo.RequestLockNumber", "SystemUserId", "dbo.SystemUser", "Id", cascadeDelete: true);
        }
    }
}
